//
//  vec2f.cpp
//  
//
//  Created by Gallienne Kevin on 03/10/13.
//
//

#include "vec2f.h"
#include <iostream>

using namespace std;

vec2f::vec2f(float a, float b){
    _data[0] = a;
    _data[1] = b;
};

vec2f::vec2f(const vec2f& other){
	 _data[0] = other.getX();
	 _data[1] = other.getY();
};

const float& vec2f::getX() const{
  cout << "Vec2f: constant access request" << endl;
  return _data[0];
};

const float& vec2f::getY() const{
  cout << "Vec2f: constant access request" << endl;
  return _data[1];
};

void vec2f::setX(float a){
    _data[0] = a;
};

void vec2f::setY(float a){
    _data[1] = a;
};
float* vec2f::getData(){
    return _data;
};

float& vec2f::x(){
  cout << "Vec2f: read  access request" << endl;
  return _data[0];
};
float& vec2f::y(){
  cout << "Vec2f: read  access request" << endl;
  return _data[1];
};

vec2f vec2f::operator+(const vec2f& a){
  vec2f res;
  res.x() = a.getX()+getX();
  res.y() = a.getY()+getY();
  return res;
};

vec2f vec2f::operator-(const vec2f& b){
  vec2f res;
  res.x() = getX()-b.getX();
  res.y() = getY()-b.getY();
  return res;
};
vec2f vec2f::operator*(const float f){
  vec2f res;
  res.x() = getX()*f;
  res.y() = getY()*f;
  return res;
};
vec2f vec2f::operator/(const float f){
  vec2f res;
  if(f==0)
  	return *this;
  res.x() = getX()/f;
  res.y() = getY()/f;
  return res;
};

const float& vec2f::operator[](const int b) const{
  return _data[b];
};

std::ostream& operator<<(std::ostream &output, vec2f a){
	output << "[" << a.x() << ", " << a.y() << "]";
	return output;            
}


